﻿Imports System.Data.OleDb
Partial Public Class discussion
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("mobilestandardsdb").ConnectionString)
        oleDbConn.Open()
        If IsPostBack() Then
            Dim sqlstr = "INSERT INTO POSTING ([Title],[Body],[AboutPaper],[UserName],[PostingDate]) VALUES (@Title,@Body,@Paper,@Username,@PostingDate)"
            Dim newCommentDbCmd As New OleDbCommand(sqlstr, oleDbConn)
            newCommentDbCmd.Parameters.AddWithValue("@Title", tbTitle.Text)
            newCommentDbCmd.Parameters.AddWithValue("@Body", tbBody.Text)
            newCommentDbCmd.Parameters.AddWithValue("@Paper", Session("articleId"))
            newCommentDbCmd.Parameters.AddWithValue("@Username", User.Identity.Name)
            newCommentDbCmd.Parameters.AddWithValue("@PostingDate", DateTime.Now.Date)

            newCommentDbCmd.ExecuteNonQuery()

        Else
            Session("articleId") = Request.Params("ID")

        End If
        ', show the paper and the comments

        Dim paperId = Session("articleId")
        

        Dim relevantPaperStr As String = "SELECT * FROM papers WHERE [ID]=@ID"

        Dim paperDbCmd As New OleDbCommand(relevantPaperStr, oleDbConn)

        paperDbCmd.Parameters.AddWithValue("@ID", paperId)

        Dim paperDbRead = paperDbCmd.ExecuteReader()

        If paperDbRead.HasRows() Then
            paperDbRead.Read()
            lblauthor.Text = paperDbRead("Author")
            lblTitle.Text = paperDbRead("Title")
            lblAbstract.Text = paperDbRead("Abstract")
        End If

        paperDbRead.Close()
        paperDbCmd.Dispose()


        




        Dim allPostingStr As String = "SELECT * FROM POSTING WHERE [AboutPaper]=@ID"

        Dim postingDbCmd As New OleDbCommand(allPostingStr, oleDbConn)

        postingDbCmd.Parameters.AddWithValue("@ID", paperId)

        Dim dbread = postingDbCmd.ExecuteReader()

        Repeater1.DataSource = dbread
        Repeater1.DataBind()


    End Sub

End Class